// worker.js
const { isMainThread, parentPort } = require('worker_threads');

if (isMainThread) {
    throw new Error('Its not a worker');
}
//生成有100个随机数的数组，并将数组排序
const taskFun = (data) => {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve(data);
        }, 2000)
    })
};
//2.子线程接收传过来的数据，并进行cpu耗时操作
parentPort.on('message', async (data) => {
    const result = await taskFun(data);
    parentPort.postMessage(result);
});